package com.zwl.sjzmanagement.controller;


import com.atguigu.tingshu.common.result.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zwl.model.Firearms;
import com.zwl.model.Materials;
import com.zwl.sjzmanagement.mapper.MaterialMapper;
import com.zwl.sjzmanagement.service.MaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/material")
public class MaterialController {

    @Autowired
    private MaterialService materialService;




    @GetMapping("/materialList")
    public Result materialList(@RequestParam(defaultValue = "1") Long pn,@RequestParam(defaultValue = "10") Long pz) {


        return Result.ok(materialService.page(new Page<>(pn,pz)));
    }


    //    http://localhost:8001/api/materials/materialsAddOrUpdate
    @PostMapping("/materialsAddOrUpdate")
    public Result materialsAddOrUpdate(@RequestBody Materials materials) {

        materialService.saveOrUpdate(materials);

        return Result.ok();
    }

//    http://localhost:8001/api/materials/materialsDelById
    @DeleteMapping("/materialsDelById/{id}")
    public Result materialsDelById(@PathVariable Integer id) {

        materialService.removeById(id);

        return Result.ok();

    }

    @PostMapping("/materialsBatchDelById")
    public Result materialsBatchDelById(@RequestBody List<Integer> ids) {

        //根据id判断，相同则执行跟新操作
        materialService.removeBatchByIds(ids);

        return Result.ok();

    }

    @GetMapping("/getMaterialsById/{id}")
    public Result getMaterialsById(@PathVariable Long id) {

        Materials materials = materialService.getById(id);
        return Result.ok(materials);

    }

}
